package
{
	import logout.net.webServices.WebServiceConnector;
	import flash.events.NetStatusEvent;
	import bi.conf.Configuration;
	import flash.events.EventDispatcher;
	import flash.events.Event;
	
	public class User extends EventDispatcher
	{
		
		public static const DATA_GRABBED : String = "dataGrabbed";
		
		public function set currentLevel( level : String ) : void {
			_currentLevel = level;
			invalidate();
		}
		public function get currentLevel() : String {
			return _currentLevel;
		}
		
		
		function User() : void {
			
		}
		
		public function grabDatas() : void {
			WebServiceConnector.instance.addEventListener( WebServiceConnector.ON_RESPONSE, onDatasGrabbed );
			WebServiceConnector.instance.addEventListener( WebServiceConnector.ON_STATUS, onDatasGrabbedError );
			WebServiceConnector.instance.call( Configuration.getInstance().getString( "grabUserDatasMethod" ) );
		}
		
		public function flushDatas() : void {
			
		}
		
		
		//_________________________________________________________________
		//															PRIVATES
		
		private function onDatasGrabbed( e : NetStatusEvent ) : void {
			WebServiceConnector.instance.removeEventListener( WebServiceConnector.ON_RESPONSE, onDatasGrabbed );
			WebServiceConnector.instance.removeEventListener( WebServiceConnector.ON_STATUS, onDatasGrabbedError );
			trace( e.info );
			for( var s : String in e.info ) {
				trace( s,"  ->  ", e.info[s] );
			}
			_currentLevel = e.info.currentLevel;
			
			syncro = true;
			
			dispatchEvent( new Event( DATA_GRABBED ) );
		}
		
		private function onDatasGrabbedError( e : NetStatusEvent ) : void {
			WebServiceConnector.instance.removeEventListener( WebServiceConnector.ON_RESPONSE, onDatasGrabbed );
			WebServiceConnector.instance.removeEventListener( WebServiceConnector.ON_STATUS, onDatasGrabbedError );
			trace( e.info );
		}
		
		
		private function invalidate() : void {
			syncro = false;
		}
		
		private var syncro : Boolean = false;
		
		private var _currentLevel : String;
	}
}